package com.sherry.base;

import com.qingqing.common.auth.domain.UserType;
import com.sherry.uitils.auth.TokenUtil;
import com.sherry.uitils.auth.IdEncoder;
import org.apache.commons.codec.digest.DigestUtils;

import java.sql.Timestamp;
import java.util.HashMap;

/**
 * Created by swl on 2021/6/21.
 */
public class HeaderMap {


    private static Long timestamp = new Timestamp(System.currentTimeMillis()).getTime();
    private static String Authkey = DigestUtils.md5Hex("qing_QiNG_jIA_JiAo!#%&@$^*" + "-" + timestamp);

    public static HashMap<String, String> addSimpleHeader(long user_id,int user_type) {
        HashMap<String, String> headermap = new HashMap<String, String>();
        String  private_key = "qing_QiNG_jIA_JiAo_crmsvc!#%&@$^*";
        String SysAuthkey = DigestUtils.md5Hex(private_key);
        String Timestamp = timestamp.toString();
        String token = TokenUtil.getuserToken(user_id, user_type);
        headermap.put("tk", token);
        headermap.put("Authkey", Authkey);
        headermap.put("Timestamp", Timestamp);
        headermap.put("qingqing_debug_mode", "true");
        headermap.put("QingqingUser", IdEncoder.encodeUser(user_type,user_id));
        headermap.put("Sys-Authkey", SysAuthkey);
        headermap.put("assistantId", String.valueOf(user_id));
        headermap.put("Content-Type","application/x-protobuf");
        return headermap;
    }

    public static HashMap<String, String> addSimpleHeader1(long user_id,int user_type) {
        HashMap<String, String> headermap = new HashMap<String, String>();
        String SysAuthkey = DigestUtils.md5Hex("qing_QiNG_jIA_JiAo_crmsvc!#%&@$^*");
        Long timestamp = TokenUtil.gettimestamp();
        String Authkey = TokenUtil.getauthkey(timestamp);
        String Timestamp = timestamp.toString();
        String token = TokenUtil.getuserToken(user_id, user_type);
        headermap.put("tk", token);
        headermap.put("Authkey", Authkey);
        headermap.put("Timestamp", Timestamp);
//        headermap.put("Date", TimeUtil.timeStampToDateFormat(timestamp));
        headermap.put("qingqing_debug_mode", "true");
        headermap.put("QingqingUser", IdEncoder.encodeUser(user_type,user_id));
        headermap.put("Sys-Authkey", SysAuthkey);
        headermap.put("assistantId", String.valueOf(user_id));
        headermap.put("Content-Type","application/x-protobuf");
        return headermap;
    }

    public static HashMap<String, String> addStuHeader(long user_id) {
        HashMap<String, String> headermap = new HashMap<String, String>();
        String token = TokenUtil.getuserToken(user_id, UserType.student.getValue());
        String session = TokenUtil.getSessionId(user_id, UserType.student.getValue());
        headermap.put("tk", token);
        headermap.put("si", session);
        headermap.put("qingqing_debug_mode", "true");
        return headermap;
    }
}
